package com.shilan.administrator.qintfm.fragment.tabhostFragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.shilan.administrator.qintfm.R;
import com.shilan.administrator.qintfm.adapter.TablayoutFragmentAdapter;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/12.
 */
public class FoundFragment extends Fragment{
    private ArrayList<Fragment> datas;
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private TablayoutFragmentAdapter adapter;
    private Context context;
    private  int position;
    public static  final  String ARGS_POSITION = "posotion";

    public static FoundFragment foundInstance(int position){
        FoundFragment f = new FoundFragment();
        Bundle args = new Bundle();
        args.putInt(ARGS_POSITION, position);
        f.setArguments(args);
        return f;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_found,null);

        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        tabLayout= (TabLayout) view.findViewById(R.id.tablayout_fragment_found);
        viewPager = (ViewPager) view.findViewById(R.id.viewPager_fragment_found);
        adapter = new TablayoutFragmentAdapter(getChildFragmentManager());
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle args = getArguments();
        if (args != null){
           position = args.getInt(ARGS_POSITION);
        }
    }
}
